package com.ruoyi.project.instrument.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.instrument.domain.InsCalibrationData;
import com.ruoyi.project.instrument.service.IInsCalibrationDataService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 试剂定标记录Controller
 *
 * @author taney
 * @date 2021-06-03
 */
@AllArgsConstructor
@RestController
@RequestMapping("/instrument/calibrationData")
public class InsCalibrationDataController extends BaseController {

    private final IInsCalibrationDataService iInsCalibrationDataService;

    /**
     * 查询试剂定标记录列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:calibrationData:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsCalibrationData insCalibrationData) {
        startPage();
        LambdaQueryWrapper<InsCalibrationData> lqw = new LambdaQueryWrapper<InsCalibrationData>();
        if (StringUtils.isNotBlank(insCalibrationData.getMachineType())) {
            lqw.eq(InsCalibrationData::getMachineType, insCalibrationData.getMachineType());
        }
        if (insCalibrationData.getProjectId() != null) {
            lqw.eq(InsCalibrationData::getProjectId, insCalibrationData.getProjectId());
        }
        if (StringUtils.isNotBlank(insCalibrationData.getCodeNo())) {
            lqw.eq(InsCalibrationData::getCodeNo, insCalibrationData.getCodeNo());
        }
        if (StringUtils.isNotBlank(insCalibrationData.getLotNo())) {
            lqw.eq(InsCalibrationData::getLotNo, insCalibrationData.getLotNo());
        }
        if (insCalibrationData.getExpireDate() != null) {
            lqw.eq(InsCalibrationData::getExpireDate, insCalibrationData.getExpireDate());
        }
        if (insCalibrationData.getRecordTime() != null) {
            lqw.eq(InsCalibrationData::getRecordTime, insCalibrationData.getRecordTime());
        }
        if (StringUtils.isNotBlank(insCalibrationData.getRecordUser())) {
            lqw.eq(InsCalibrationData::getRecordUser, insCalibrationData.getRecordUser());
        }
        List<InsCalibrationData> list = iInsCalibrationDataService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出试剂定标记录列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:calibrationData:export')")
    @Log(title = "试剂定标记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InsCalibrationData insCalibrationData) {
        LambdaQueryWrapper<InsCalibrationData> lqw = new LambdaQueryWrapper<InsCalibrationData>(insCalibrationData);
        List<InsCalibrationData> list = iInsCalibrationDataService.list(lqw);
        ExcelUtil<InsCalibrationData> util = new ExcelUtil<InsCalibrationData>(InsCalibrationData.class);
        return util.exportExcel(list, "calibrationData");
    }

    /**
     * 获取试剂定标记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:calibrationData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(iInsCalibrationDataService.getById(id));
    }

    /**
     * 新增试剂定标记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:calibrationData:add')")
    @Log(title = "试剂定标记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsCalibrationData insCalibrationData) {
        return toAjax(iInsCalibrationDataService.save(insCalibrationData) ? 1 : 0);
    }

    /**
     * 修改试剂定标记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:calibrationData:edit')")
    @Log(title = "试剂定标记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsCalibrationData insCalibrationData) {
        return toAjax(iInsCalibrationDataService.updateById(insCalibrationData) ? 1 : 0);
    }

    /**
     * 删除试剂定标记录
     */
    @PreAuthorize("@ss.hasPermi('instrument:calibrationData:remove')")
    @Log(title = "试剂定标记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(iInsCalibrationDataService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
